/* 
 * Copyright (c)	Insighten Intelligent Equipment co.,LTD
 * 
 *  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * 
 */
/** 
 * @file cmsgsvr_main.c
 * @brief test for communication
 * @author taco [tacoee@gmail.com]
 * @version 0.1
 * @date 2010-09-14
 */
#include "types.h"
#include "rwbuf.h"
#include "communication.h"
#include "cmsg.h"

int print_string(RwBuf **in, RwBuf **out, MsgCmd cmd)
{
	RwBuf *inp = *in;
	return_val_if_fail((*in) != NULL, -1);

	fprintf(stderr, "%s", inp->mem);

	*out = *in;

	return 0;
}

int main(int argc, char *argv[])
{
	CommObj *cobj = NULL;
	RwBuf *ori_buf = NULL;
	int ret;

	cobj = comm_obj_open(cobj, MSG_KEY_G, SHM_KEY_G, SHM_SIZE); 

	comm_obj_set_msg_type(cobj, MSG_TYPE_OSD, MSG_TYPE_CLI);

	system("ipcs");

	ori_buf = buf_new(NULL, NULL);
	buf_init(ori_buf, 1024);

	ret = sprintf(ori_buf->mem, "are u sitll ok? good luck to you,funcation=%s,line=%d", __func__, __LINE__);
	buf_update_wpos(ori_buf, ret);
	dbg_log("wpos = %d", ret);
	dbg_log("wpos = %d", ori_buf->wpos);
	comm_obj_snd_rcv(cobj, print_string, ori_buf);

	buf_destroy(ori_buf);
	comm_obj_close(cobj);

	return 0;
}
